
import { _decorator, Component,Label, Animation,Button, Node } from 'cc';
import { BytePlantform}  from "../Tool/BytePlantform";
import { ReactiveAutoSave } from "../Tool/ReactiveAutoSave"
const { ccclass, property } = _decorator;



@ccclass('slider_page')
export class slider_page extends Component {

    @property({ type: Label })
    public btn_label: Label; 
   

    @property({ type: Button})
    slider_button: Button = null;

    private static _ins: slider_page | null = null; // 单例实例

    // 单例模式：获取实例
    public static get ins(): slider_page {
        return this._ins;
    }

    start() {
         // 设置单例实例
        slider_page._ins = this;
        this.refrush_data();
    }

    public refrush_data(){
        console.log("refrush_data");
        if(ReactiveAutoSave.ins.getData().gift == 0){
            //0 =default,1=添加了。2=领取奖励
            this.btn_label.string = "跳转侧边栏"
         }else if(ReactiveAutoSave.ins.getData().gift == 1){
            //0 =default,1=添加了。2=领取奖励
            this.btn_label.string = "领取奖励"
         }else{
             this.btn_label.string = "跳转侧边栏"
         }
    }
    
    btn_run(){
        console.log("btn_run");
        if(ReactiveAutoSave.ins.getData().gift == 0){
            this.add_siderbar();
         }else if(ReactiveAutoSave.ins.getData().gift == 1){
            this.get_gift();
         }else{
            this.add_siderbar();
         }
    }

    private get_gift(){
        ReactiveAutoSave.ins.getData().gift = 2;
        this.slider_button.interactable = false;
    }


   private add_siderbar() {
         // 调用SDK接口
         console.log("开始添加 add_siderbar");
         BytePlantform.ins.navigate_to_douyin((success: boolean) => {
            if (success) {
                // this.node.active = false;
                console.log('add_siderbar 添加侧边栏跳转成功');
                // if(LvLStorage.get_gift()<1){
                //     LvLStorage.record_gift(1);
                //     console.log('add_siderbar 添加侧边栏跳转成功,记录数据 1');
                // }
            } else {
                console.log('add_siderbar 跳转失败');
            }
        });
    }

}


